package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.chenfeng.vo.StatGoodsVo;
import com.cskaoyan.bean.chenfeng.vo.StatOrderVo;
import com.cskaoyan.bean.chenfeng.vo.StatUserVo;
import com.cskaoyan.service.StatService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Chen_Feng
 * @since 2022/06/28 23:30
 */
@RestController
@RequestMapping("admin/stat")
public class StatController {

    @Autowired
    StatService statService;

    /**
     * 查询用户统计新增数据
     *
     * @return com.cskaoyan.bean.BaseRespVo<com.cskaoyan.bean.chenfeng.vo.StatUserVo>
     * @author Chen_Feng
     * @since 2022/06/29 0:39
     */
    @RequiresPermissions(value = {"admin:stat:user", "*"}, logical = Logical.OR)
    @RequestMapping("user")
    public BaseRespVo<StatUserVo> user() {

        // 执行StatService业务
        StatUserVo data = null;
        try {
            data = statService.getUserStatData();
            return BaseRespVo.ok(data);
        } catch (Exception e) {
            e.printStackTrace();
            return BaseRespVo.invalidData("数据很调皮，躲起来了");
        }
    }

    @RequiresPermissions(value = {"admin:stat:order", "*"}, logical = Logical.OR)
    @RequestMapping("order")
    public BaseRespVo<StatOrderVo> order() {

        // 执行StatService业务
        StatOrderVo data = null;
        try {
            data = statService.getOrderStatData();
            return BaseRespVo.ok(data);
        } catch (Exception e) {
            e.printStackTrace();
            return BaseRespVo.invalidData("数据很调皮，躲起来了");
        }
    }

    /**
     * 显示商品数据统计
     *
     * @return com.cskaoyan.bean.BaseRespVo<StatGoodsVo>
     * @author Chen_Feng
     * @since 2022/06/29 1:59
     */
    @RequiresPermissions(value = {"admin:stat:goods", "*"}, logical = Logical.OR)
    @RequestMapping("goods")
    public BaseRespVo<StatGoodsVo> goods() {

        // 执行StatService业务
        StatGoodsVo data = null;
        try {
            data = statService.getGoodsStatData();
            return BaseRespVo.ok(data);
        } catch (Exception e) {
            e.printStackTrace();
            return BaseRespVo.invalidData("数据很调皮，躲起来了");
        }
    }
}
